home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZDebug.h
< prev
next >
Wrap
Text File
|
1997-05-17
|
5KB
|
146 lines
/*
* File: ZDebug.h
* Summary: Debugging functions and macros.
* Written by: Jesse Jones
*
* Copyright ゥ 1996-1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Abstract: This file provides the following macros:
*
* ASSERT(x) - If x is false and DEBUG is true drops into the
* debugger, if ASSERTS_THROW is true throws a TAssertException exception.
*
* VERIFY(x) - Like ASSERT except that x is evaluated in release builds.
*
* DEBUGSTR(formatStr, n1, n2, ...) - Drops into the debugger and
* displays a string.
*
* TRACE(formatStr, n1, n2, ...) - Writes a string to a debug window
* without suspending the program.
*
* TRACEFLOW(category, formatStr, n1, n2, ...) - Like TRACE, but with
* the addition of a category string. The category string allows users
* to turn off entire categories of messages. Note that DEBUGSTR, TRACE,
* and TRACEFLOW may be used with boolean expressions by tacking an _IF
* on the end (eg DEBUGSTR_IF(x < 0, "Sqrt was passed a negative argument.")).
*
* PRECONDITION(x) - Used in conjunction with POSTCONDITION to verify
* the integrity of an object: each public method should include one call to
* PRECONDITION and another to POSTCONDITION. The idea here is to check to
* see if the object stays in a valid state given valid arguments. Note that
* these macros call a method named Invariant. This method should use ASSERT's
* to check to see if the object is in a sane state. See ZInvariant.h for
* more details.
*
* Change History (most recent first):
*
* <4> 5/17/97 JDJ PRECONDITION casts 'this' to an MInvariant*.
* <3> 4/12/97 JDJ If !DEBUG && ASSERTS_THROW PRECONDITION and POSTCONDITION
* map to ASSERT (instead of no-ops). If DEBUG PRECONDITION
* uses new ZCheckInvariant class (see ZInvariant.h).
* <2> 12/05/96 JDJ Exposed the break to debugger functions.
* <1> 1/13/96 JDJ Created.
*/
#pragma once
#include <Windows.h>
#include <Assert.h>
#include <ZInvariant.h>
// Synch with ANSI definitions.
#if DEBUG && defined(NDEBUG)
#error DEBUG and NDEBUG are out of sync!
#endif
#if !DEBUG && !defined(NDEBUG)
#error DEBUG and NDEBUG are out of sync!
#endif
// Synch with MacApp qDebug.
#if DEBUG != qDebug
#error DEBUG and qDebug are out of sync!
#endif
extern bool gMonkeyLives; // true if the monkey is awake
void BreakToDebugger(); // these ignore the DEBUG flag so be very careful how you use them!
void BreakStrToDebugger(const char* mesg);
#if DEBUG
extern bool gIntenseDebugging; // defaults to false
extern bool gBreakOnAssert; // defaults to true
WindowRef GetSIOUXWindow();
void DEBUGSTR(const char* format, ...);
void TRACEFLOW(const char* category, const char* format, ...);
void DEBUGSTR_IF(bool cond, const char* format, ...);
void TRACE_IF(bool cond, const char* format, ...);
void TRACEFLOW_IF(bool cond, const char* category, const char* format, ...);
void AssertFailed(const char* expr, const char* file, int line);
void SafeAssertFailed(const char* expr, const char* file, int line);
#undef assert
#define ASSERT(x) do {if (!(x)) AssertFailed(#x, __FILE__, __LINE__);} while (false)
#define assert(x) ASSERT(x)
#define VERIFY(x) ASSERT(x)
#define PRECONDITION(x) ASSERT(x); ¥
const MInvariant* _object = dynamic_cast<const MInvariant*>(this); ¥
ASSERT(_object != nil); ¥
ZCheckInvariant _check(_object)
#define POSTCONDITION(x) ASSERT(x)
void TRACE(const char* format, ...);
// Interrupt safe debug macros
void SAFE_DEBUGSTR(const char* str);
void SAFE_DEBUGSTR(const char* str, long num);
#define SAFE_ASSERT(x) do {if (!(x)) SafeAssertFailed(#x, __FILE__, __LINE__);} while (false)
#else // #if DEBUG
inline void __DUMMY_TRACE__(...) {}
#define DEBUGSTR 1 ? ((void) 0) : __DUMMY_TRACE__
#define TRACEFLOW 1 ? ((void) 0) : __DUMMY_TRACE__
#define DEBUGSTR_IF 1 ? ((void) 0) : __DUMMY_TRACE__
#define TRACE_IF 1 ? ((void) 0) : __DUMMY_TRACE__
#define TRACEFLOW_IF 1 ? ((void) 0) : __DUMMY_TRACE__
#if ASSERTS_THROW
void AssertFailed(const char*, const char*, int);
#define ASSERT(x) do {if (!(x)) AssertFailed(#x, __FILE__, __LINE__);} while (false)
#define VERIFY(x) ASSERT(x)
#define PRECONDITION(x) ASSERT(x)
#define POSTCONDITION(x) ASSERT(x)
#else
#define ASSERT(x) ((void) 0)
#define VERIFY(x) do {if (x) ;} while (false)
#define PRECONDITION(x) ((void) 0)
#define POSTCONDITION(x) ((void) 0)
#endif
#define TRACE 1 ? ((void) 0) : __DUMMY_TRACE__
#define SAFE_DEBUGSTR 1 ? ((void) 0) : __DUMMY_TRACE__
#define SAFE_ASSERT(x) ((void) 0)
#endif // DEBUG